Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Google Script - How to add a function in value="" in HTML with a JS function?

So it's my first post ever on StackOverflow, so sorry if I tell something weird:

So, I would like to display the date from the function Today() in my input with the id "file_name" (so, it will be like a default value):

webAppBoot.html

<!DOCTYPE html>
<html>

<head>
  <?!= include('WebAppBoot-css'); ?>
</head>

<body>
    <form>
        <div class="input-field col s6">
          <input id="file_name" type="text" class="validate">
          <label for="file_name">File name</label>
        </div>
    </form>
<?!= include('WebAppBoot-js'); ?>
</body>

</html>

index.gs

function doGet(request) {
  return HtmlService.createTemplateFromFile('WebAppBoot')
      .evaluate();
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}

I know that I can totally write the function Today() from this file WebAppBoot-js.html

<script>
    document.getElementById("file_name").value = google.script.run.Today();    
</script>

But I prefer to add it from this file : functions.gs

  function Today() {
  var today = new Date();
  var dd = String(today.getDate()).padStart(2, '0');
  var mm = String(today.getMonth() + 1).padStart(2, '0')
  var yyyy = today.getFullYear();
  return mm + '/' + dd + '/' + yyyy;
}

So, as I tried, it's not working as you can see: undefined value

But I can still see that the function is working with a Logger.log(Today()) function So, to resume, in definitive, I would like to have that when we open the form:Final result

Can you help me ? Thank you

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!